#include<stdio.h>
#include<string.h>
#define SIZE 1000000
void printPalindrome(char *str)
{
    int i,j,n,c=0;
    char target[SIZE];
    char ch;
    n =strlen(str);
    target[n] = 0;
    for(i=0;i<(n+1)/2;i++)
    {
        target[i]=target[n-1-i] = str[i];
    }
    if(strcmp(str,target) >= 0)
    {
        i--;
        c = 1;   
        while(c&&i >=0)
        {   

            if((target[i]+1 - '0') == 10)
            {
                   
                target[i] = target[n-1-i] ='0';
                c = 1;
                i--;

            }
            else
            {
                target[i] = target[n-1-i] = target[i]+1;
                c=0;
            }
        }
    }
    if(c == 1)
    {
        n = strlen(target);
        printf("\n1");
        for(i=0;i<n-1;i++)
            printf("0");   
        printf("1");
    }
    else
    {
        printf("\n%s",target);
    }
}
int main()
{
    int i,n;
    char str[10][SIZE];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",str[i]);
    }
   
    for(i=0;i<n;i++)
    {
        printPalindrome(str[i]);
    }
    return 0;
}